package control;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.manager.ManagerService;
import model.vo.Item_dataVO;
import model.vo.TrackingVO;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

public class ManagerController extends MultiActionController {
	private int quantity;
	private ManagerService managerService;
	private MachineController mc;
	public void setmachineController(MachineController mc) {
		this.mc = mc;
	}
	public void setManagerService(ManagerService managerService){
		this.managerService=managerService;
	}
	public ModelAndView workOrderResultState(HttpServletRequest request,
			HttpServletResponse response) throws SQLException{
		HashMap map = new HashMap();
		map.put("state", "start");
		map.put("result", 5);		
		return new ModelAndView("JsonView","map",map);
	}
	public void workProduction(HttpServletRequest request,
			HttpServletResponse response) throws SQLException{
		int workorder_quantity = Integer.parseInt(request.getParameter("workorder_quantity"));
		int speed = Integer.parseInt(request.getParameter("speed"));
		mc.workOrderInsert(workorder_quantity,speed);
	}
	public ModelAndView production_view(HttpServletRequest request,
			HttpServletResponse response) throws SQLException{
		HashMap production_map = mc.production_view();
		return new ModelAndView("JsonView","production_map",production_map);
	}
	// 원료 주문시,
		public void itemDataInsert(HttpServletRequest request,
				HttpServletResponse response) throws SQLException{
			int soap_base=Integer.parseInt(request.getParameter("soap_base"));
			int oil=Integer.parseInt(request.getParameter("oil"));
			int hardener=Integer.parseInt(request.getParameter("hardener"));
			int wrapper=Integer.parseInt(request.getParameter("wrapper"));
			Item_dataVO ivo=new Item_dataVO();
			Item_dataVO ivo1=new Item_dataVO();
			Item_dataVO ivo2=new Item_dataVO();
			Item_dataVO ivo3=new Item_dataVO();
			ArrayList ilist=new ArrayList();
			ivo.setItem_id("soap_base");ivo.setitem_oriquantity(soap_base);ilist.add(ivo);
			ivo1.setItem_id("oil");ivo1.setitem_oriquantity(oil);ilist.add(ivo1);
			ivo2.setItem_id("hardener");ivo2.setitem_oriquantity(hardener);ilist.add(ivo2);
			ivo3.setItem_id("wrapper");ivo3.setitem_oriquantity(wrapper);ilist.add(ivo3);
			//System.out.println(ilist);
			managerService.itemDataInsert(ilist);
		}
		//원료 리스트 받기,
		public ModelAndView itemDataList(HttpServletRequest request,
				HttpServletResponse response) throws SQLException{
			List<Item_dataVO> itemList = managerService.itemDataList();
			//System.out.println(itemList);
			return new ModelAndView("JsonView","itemlist",itemList);
		}
		//추적 리스트 받기,
		public ModelAndView TrackingList(HttpServletRequest request,
				HttpServletResponse response) throws SQLException{
			List<TrackingVO> trackingList = managerService.TrackingList();
			System.out.println(trackingList);
			return new ModelAndView("JsonView","trackingList",trackingList);
		}
	
}
